package volatiles;

import java.util.concurrent.TimeUnit;

/**
 * @Author Klys
 * @Date 2023/4/22 16:14
 * @Description
 * @Version 1.0
 */
public class Test01 {
    public static void main(String[] args) {
        Shop shop = new Shop();

        new Thread(() -> {
            System.out.println("线程A初始化");
            try {
                TimeUnit.SECONDS.sleep(3);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            shop.saleOne();
            System.out.println("线程A购买商品完成，剩余商品量：" + shop.a);
        }, "线程A").start();

        while (shop.a == 1) {
            System.out.println("a==1");
        }

        System.out.println("主线程，剩余商品量：" + shop.a);
    }
}
